var app = getApp();

Component({
    "options": {
        styleIsolation: "isolated"
    },
    properties: {
        "banner": {type: Array}
    },
    data: {
        banner: ''
    },
    lifetimes: {
        attached: function () {

        },
    },
    observers: {},
    methods: {
        search: function () {
            wx.navigateTo({
                url: "/pages/index/search/search"
            })
        },

        jumpType: function (e) {
            let item = e.currentTarget.dataset.item;
            switch (item[`link_type`]) {
                case 0:
                    let id = item[`category_id`];
                    wx.setStorage({key: "category_id", id})
                    let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
                    if (extConfig.category = null || extConfig.category == 0) {

                        wx.navigateTo({
                            url: '/pages/index/categorysku/categorysku',
                        })
                    } else {
                        wx.navigateTo({
                            url: '/pages/index/newcategory/newcategory?id=' + id,
                        })
                    }
                    break;
                case 1:
                    wx.navigateTo({
                        url: '/pages/index/brandsku/brandsku?id=' + item['topic_id']
                    })
                    break;
                case 2:
                    wx.navigateTo({
                        url: `/pages/index/webView/webView?src=${item.link}`
                    })
                    break;
            }
        },


        isTarbar: function (src) {
            const arr = [
                '/pages/index/index',
                '/pages/index/categorysku/categorysku',
                '/pages/tool/tools/tools',
                '/pages/about/about',
            ];
            return arr.includes(src);
        },
        isRoomId: function (src) {
            return src.includes('roomid');
        },
        liveplayer(src) {
            let roomId = src.split('/')[1];
            let customParams = encodeURIComponent(JSON.stringify({path: 'pages/index/index', pid: 1}));
            wx.navigateTo({
                url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${customParams}`
            })
        },

        onbanner: function (e) {
            let src = e.currentTarget.dataset.link;
            let result = this.isTarbar(src);
            let roomID = this.isRoomId(src);
            if (result) {
                wx.switchTab({
                    url: src
                })
            } else if (roomID) {
                this.liveplayer(src);
            } else {
                wx.navigateTo({
                    url: src
                })
            }
        },
    }
});
